De: Lucas Teodoro Magela Costa
Enviado: sexta-feira, 18 de maio de 2012 16:13
Para: casteodoro@gmail.com
Assunto:

http://www.loiane.com/2010/01/tutorial-comecando-com-spring-security/

 

http://static.springsource.org/spring-security/site/docs/3.0.x/reference/appendix-schema.html

 

http://www.javasimples.com.br/spring-2/spring-security-3-deixando-sua-aplicacao-web-segura

 

http://www.jroller.com/habuma/entry/method_level_security_in_spring

 

http://jamacedo.com/2011/01/crud-jsf-2-parte-3-seguna-com-spring-security-3/

 

http://javafaces.wordpress.com/2011/01/03/spring-security-hibernate/

 

 

 

package br.com.gsa.model;

 

import javax.persistence.Column;

import javax.persistence.Entity;

import javax.persistence.JoinColumn;

import javax.persistence.OneToMany;

import javax.persistence.Table;

import javax.validation.constraints.NotNull;

import javax.validation.constraints.Size;

 

@Entity

@Table(name="AUTHORITIES", schema="APP")

public class Authorities {

     

      @NotNull

      @Size(min = 1, max = 50)

      @Column(unique = true)

      private String username;

     

     

      @NotNull

      @Size(min = 1, max = 50)

      @JoinColumn(name="USERNAME")

      @OneToMany 

      private String authority;

 

 

      public String getUsername() {

            return username;

      }

 

 

      public void setUsername(String username) {

            this.username = username;

      }

 

 

      public String getAuthority() {

            return authority;

      }

 

 

      public void setAuthority(String authority) {

            this.authority = authority;

      }

     

}

 

 

 

 

 

 

 

 

 

 

package br.com.gsa.model;

 

import java.io.Serializable;

import java.util.ArrayList;

import java.util.Collection;

import java.util.List;

 

import javax.persistence.Column;

import javax.persistence.Entity;

import javax.persistence.FetchType;

import javax.persistence.GeneratedValue;

import javax.persistence.GenerationType;

import javax.persistence.Id;

import javax.persistence.ManyToMany;

import javax.persistence.NamedQueries;

import javax.persistence.NamedQuery;

import javax.persistence.Table;

import javax.persistence.Transient;

import javax.validation.constraints.NotNull;

import javax.validation.constraints.Size;

 

import org.springframework.security.core.GrantedAuthority;

import org.springframework.security.core.authority.GrantedAuthorityImpl;

import org.springframework.security.core.userdetails.UserDetails;

 

@Entity

@Table(name="USERS", schema="APP")

@NamedQueries({

@NamedQuery(name = "findByUsername", query = "SELECT usu FROM Users usu WHERE usu.username = :username"),

@NamedQuery(name = "findAll", query = "SELECT usu FROM Users usu")

})

 

public class Users implements Serializable, UserDetails {

 

  private static final long serialVersionUID = -8451679170281063697L;

 

  @Id

  @GeneratedValue(strategy = GenerationType.AUTO)

  private Long id;

 

  @NotNull

  @Size(min = 1, max = 50)

  @Column(unique = true)

  private String username;

 

  @NotNull

  @Size(min = 1, max = 50)

  private String password;

 

  @ManyToMany(fetch = FetchType.EAGER)

  private List<Authorities> authorities;

 

  @NotNull

  private boolean enabled;

 

  @Transient

  public Collection<GrantedAuthority> getAuthorities() {

    List<GrantedAuthority> result =

    new ArrayList<GrantedAuthority>();

    for (Authorities aut : authorities) {

      result.add(new GrantedAuthorityImpl(aut.getAuthority()));

    }

    return result;

  }

 

 

  public boolean isEnabled() {

                return enabled;

}

 

 

public void setEnabled(boolean enabled) {

                this.enabled = enabled;

}

 

 

public void setUsername(String username) {

                this.username = username;

}

 

 

public void setPassword(String password) {

                this.password = password;

}

 

 

public void setAuthorities(List<Authorities> authorities) {

                this.authorities = authorities;

}

 

 

@Transient

  public boolean isAccountNonExpired() {

    return true;

  }

 

  @Transient

  public boolean isAccountNonLocked() {

    return true;

  }

 

  @Transient

  public boolean isCredentialsNonExpired() {

    return true;

  }

 

  public String getUsername() {

    return username;

  }

 

  public String getPassword() {

    return password;

  }

}

 

	

Lucas Teodoro Magela Costa
Programador

+55 31 2534-5750 (Phone)
lucas.costa@cast.com.br
www.cast.com.br

Before printing, please consider the economy and environment.     

This message contains confidential information. If, by any mistake, you are not the intended recipient, you may not use, copy, disseminate or disclose any information contained in the message. If you have it in error, please advise the sender and delete the message. Thank you!           

 

 
